<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/newTabStyle.css" TYPE="text/css"
	MEDIA="screen">
<script type="text/javascript">
var win_id;
var tab_index;
var results;

function createTabData(url) {
	return {
		'index' : tab_index + 2,
		'windowId' : win_id,
		'url' : url,
		'selected' : true
	};
}
function openLink(url) {
	var args = createTabData(url);
	try {
		chrome.tabs.create(args);
	} catch (e) {
		alert(e);
	}
}
function setLinks(links) {
	var table = document.getElementById("tableLinks");
	for ( var i = 0; i < links.length; i++) {
		var link = links[i];
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);

		var cell1 = row.insertCell(0);
		cell1.innerHTML = "";// discovery.priority;

		var cell2 = row.insertCell(1);
		var element = document.createElement("a");
		element.setAttribute("class", "links");
		element.setAttribute("onclick", "openLink('" + link.url + "')");
		element.innerHTML = link.description + "  <font color=gray>(" + link.url +")</font>";
		cell2.appendChild(element);

		var cell3 = row.insertCell(2);
		cell3.innerHTML = "";
		var row = table.insertRow(rowCount+1);
		var cell1 = row.insertCell(0);
		cell1.innerHTML = "";//
		var cell2 = row.insertCell(1);
		cell2.innerHTML = "<hr>";
		var cell3 = row.insertCell(2);
		cell3.innerHTML = "";
	}
}
function setTitle(title) {
	document.title = title;
	document.getElementById("lblGroup").innerHTML = title;
}
function load(){
	var bg = chrome.extension.getBackgroundPage();
	res = bg.getGroupLinks();
	win_id = res.win_id;
	tab_index = res.tab_index;
	setLinks(res.discoveries);
	setTitle(res.group);
}
</script>
<title>Insert title here</title>
</head>
<body onload="load()">
<h1>Links extracted from <font color=red ><label id=lblGroup></label></font></h1>
<table width="800" cellspacing="0" cellpadding="1" id="tableLinks"
	style='table-layout: fixed; word-break: break-all'>
	<col width=20>
	<col width=760>
	<col width=20>
	<tbody>
		<tr>
			<td width="20"></td>
			<td width="760"><i>&nbsp;</i></td>
			<td width="20"></td>
		</tr>
	</tbody>
</table>
</body>
</html>